package com.hx.company.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.hx.company.dao.ManagerDao;
import com.hx.company.vo.Admin;
import com.hx.company.vo.Merchant;
import com.hx.company.vo.UserLogin;

@Repository("md")
public class AdminDaoImpl implements ManagerDao{
	@PersistenceContext(name="un")
	private EntityManager em;
	@Override
	public List<Admin> find(Admin a) {
		String s="select c from Admin c where c.aname=:aname";
		List<Admin> cs=em.createQuery(s)
				.setParameter("aname", a.getAname())
				.getResultList();
	return cs;
	}
	

	@Override
	public Admin addAdmin(Admin a) {
	em.persist(a);
		return a;
		
		// TODO Auto-generated method stub
		
	}


	@Override
	public List<Merchant> findAll() {
		String s=" from Merchant c";
		List<Merchant> mc=em.createQuery(s)
				.getResultList();
		
		System.out.println(mc.get(0).getMname()+"@@@@@");
		return mc;
	}


	@Override
	public boolean accMercha(int id) {
		// TODO Auto-generated method stub
		Merchant me=em.find(Merchant.class,id);
		me.setTemp(1);
	    return true;
	}


	@Override
	public void deleteMerch(int id) {
		// TODO Auto-generated method stub
		 Merchant mer=em.find(Merchant.class,id);
      	em.remove(mer);
	}
	
	
}
